<?php

namespace App\model\customer;

use App\User;
use Illuminate\Database\Eloquent\Model;

/**
 * App\model\customer\CustomerSecondDepart
 *
 * @property int $id
 * @property string|null $name
 * @property int|null $sort
 * @property int|null $parent_id
 * @property string|null $user_ids
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\User[] $children
 * @property-read int|null $children_count
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\CustomerSecondDepart newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\CustomerSecondDepart newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\CustomerSecondDepart query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\CustomerSecondDepart whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\CustomerSecondDepart whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\CustomerSecondDepart whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\CustomerSecondDepart whereParentId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\CustomerSecondDepart whereSort($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\CustomerSecondDepart whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\CustomerSecondDepart whereUserIds($value)
 * @mixin \Eloquent
 * @property int|null $number
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\User[] $user
 * @property-read int|null $user_count
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\CustomerSecondDepart whereNumber($value)
 * @property-read \App\model\customer\CustomerBigDepart|null $parent
 */
class CustomerSecondDepart extends Model
{
    protected $table='customer_second_depart';
    public function getUserIdsAttribute($value)
    {
        return explode(',', $value);
    }
    public function setUserIdsAttribute($value)
    {
        $this->attributes['user_ids'] = implode(',', $value);
    }
    public function user(){
        return $this->hasMany(User::class,'department_id');
    }
    public function parent(){
        return $this->belongsTo(CustomerBigDepart::class,'parent_id');
    }
    public function children(){
        return $this->hasMany(User::class,'department_id');
    }
}
